﻿using Iworld.Author.Model;
using Iworld.Author.Service.Client.Export;
using Iworld.basis.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Author.Service.Client.Import
{
    /// <summary>
    /// 获取提现记录数据集
    /// </summary>
   [DataContract]
   public class GetWithdrawalsRecordExportsImport : GetPageListCheckAuthorImportBase
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        [DataMember]
        public DateTime? BeginTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        [DataMember]
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 当前状态
        /// </summary>
        [DataMember]
        public WithdrawalsStatus? Status { get; set; }

        public PageResult<WithdrawalsRecordExport> GetWithdrawalsRecordExports(IModelToDbContextOfAuthor db)
        {
            int pageSize = 10;
            int startRow = pageSize * (this.PageIndex - 1);
            IQueryable<WithdrawalsRecord> temp = db.WithdrawalsRecords.Where(x=>x.Owner.Id == Self.Id);
            if (BeginTime != null)
            {
                temp = temp.Where(x => x.CreatedTime > (DateTime)BeginTime);
            }
            if (EndTime != null)
            {
                temp = temp.Where(x => x.CreatedTime < (DateTime)EndTime);
            }
            if (Status != null)
            {
                temp = temp.Where(x => x.Status == (WithdrawalsStatus)Status);
            }
            int totalCount = temp.Count();
            var list = temp.OrderByDescending(x => x.CreatedTime).Skip(startRow).Take(pageSize).ToList().ConvertAll(x =>
            {
                return new WithdrawalsRecordExport(x);
            });

            return new PageResult<WithdrawalsRecordExport>(this.PageIndex, totalCount, pageSize, list);
        }
    }
}
